package org.funtester.performance.books.chapter10.section4;

import org.funtester.performance.books.chapter09.section3.UserBehavior;

public class FunPoolTest {

    public static void main(String[] args) {
        FunPool<UserBehavior> userBehaviorFunPool = new FunPool<>(() -> new UserBehavior());
        UserBehavior userBehavior = userBehaviorFunPool.borrow();
        userBehavior.id = 1;// 设置用户id
        userBehavior.action = "login";// 设置用户行为
        userBehavior.content = "地点北京";// 设置用户行为内容
        userBehavior.timestamp = System.currentTimeMillis();// 设置用户行为时间戳
        System.out.println("第一次借出对象hashCode: " + userBehavior.hashCode());// 打印对象的hashcode
        System.out.println(userBehavior);// 打印对象内容
        userBehavior.id = 2;// 设置用户id
        userBehavior.action = "login";// 设置用户行为
        userBehavior.content = "地点河北";// 设置用户行为内容
        userBehavior.timestamp = System.currentTimeMillis();// 设置用户行为时间戳
        userBehaviorFunPool.back(userBehavior);// 归还对象
        UserBehavior userBehaviorSecond = userBehaviorFunPool.borrow();// 再次获取对象
        System.out.println("第二次借出对象hashCode: " + userBehaviorSecond.hashCode());// 打印对象的hashcode
        System.out.println(userBehaviorSecond);// 打印对象内容
    }

}
